import Koa from "koa";
import koaCors from "koa-cors";
import koaXmlBody from "koa-xml-body";
import koaBody from "koa-body";
import router from "./routers/index";
import wrapper from "./middlewares/wrapper";
import { appname, env, port } from "./common/config";
import { getTime } from "./utils/time";

const app = new Koa();
app.proxy = true;

// 配置koa
app.use(koaCors());
app.use(koaXmlBody());
app.use(koaBody({
  patchNode: true,
  patchKoa: false,
  multipart: true,
  jsonLimit: "10mb",
  textLimit: "10mb",
  formLimit: "10mb",
  formidable: {
    maxFileSize: 200 * 1024 * 1024
  }
}));

app.use(wrapper());
app.use(router.routes());
app.use(router.allowedMethods());

app.on("error", err => {
  console.log("server error", err);
});

app.listen(port);

// 欢迎信息
console.log(`【 ${getTime()} 】 🚀 服务启动成功，项目名：${appname}，当前环境：${env}，监听端口:${port} 🚀 `);
